/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-wechatpush
*
* @File name : InsuranceExpireService.java
*
* @Author : Administrator
*
* @Date : 2017年7月26日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年7月26日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.service.wechatpush.event.service;

import static org.marketing.common.constants.MessagePushConstant.WX_MSG_PROP_COLOR;


import org.marketing.common.constants.BusinessConstant;
import org.marketing.common.constants.MessagePushConstant;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageTemplateContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolReceiver;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolSender;
import org.marketing.common.event.EventInsuranceExpireDTO;
import org.marketing.common.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
*
* @author Administrator
* TODO description
* @date 2017年7月26日
*/
@Service
public class InsuranceExpireService {
    private static Logger logger = LoggerFactory.getLogger(InsuranceExpireService.class);
    
    public WeChatMessageProtocol getWXTemplate(EventInsuranceExpireDTO o){
        WeChatMessageProtocol messageProtocol = new WeChatMessageProtocol();

        WeChatMessageProtocolReceiver receiver = new WeChatMessageProtocolReceiver();
        receiver.setDetail(true);
        receiver.setPlatform(MessagePushConstant.PUSH_PLATFORM.WC_PUBLIC);
        receiver.addDetailList(o.getOpenId());

        WeChatMessageProtocolMessageContent message = new WeChatMessageProtocolMessageContent();
        //保险到期提醒
        message.setContent("TM00619");
        
        message.setSourceType(BusinessConstant.SOURCE_TYPE_WECHAT);

        WeChatMessageProtocolMessageTemplateContent content1 = new WeChatMessageProtocolMessageTemplateContent();
        content1.setKey("first");
        content1.setValue("您的爱车保险即将到期，建议您尽快续保。");
        message.addTemplateConentList(content1);

        WeChatMessageProtocolMessageTemplateContent content2 = new WeChatMessageProtocolMessageTemplateContent();
        content2.setKey("keynote1"); 
        content2.setValue(DateUtil.formateDate(o.getInsuranceStartDate(), "yyyy-MM-dd"));
        message.addTemplateConentList(content2);

        WeChatMessageProtocolMessageTemplateContent content3 = new WeChatMessageProtocolMessageTemplateContent();
        content3.setKey("keynote2");
        content3.setValue(DateUtil.formateDate(o.getInsuranceEndDate(), "yyyy-MM-dd"));
        message.addTemplateConentList(content3);
        
        WeChatMessageProtocolMessageTemplateContent content4 = new WeChatMessageProtocolMessageTemplateContent();
        content4.setKey("remark");
        content4.setValue("");
        message.addTemplateConentList(content4);

        WeChatMessageProtocolSender sender = new WeChatMessageProtocolSender();
        sender.setOriginApplicationHost("host1");
        sender.setOriginApplicationName("app1");
        sender.setClientAppId("wxb85ed633e428bafc");
        sender.setDealerCode("00000");
        messageProtocol.setMessage(message);
        messageProtocol.setReceiver(receiver);
        messageProtocol.setSender(sender);
        messageProtocol.setPushChannel(MessagePushConstant.PUSH_CHANNEL.WEBCHAT);

        return messageProtocol;
    }
}
